package main


import (
	"strconv"
	"strings"
)

func replace(num int, a byte) int {
	i := 0
	s := strconv.Itoa(num)
	for ; i < len(s); i++ {
		if s[i] == a || (s[i] == '1' && a == '0') {
			continue
		}
		break
	}
	if i < len(s) {
		t := s[i]
		s = strings.ReplaceAll(s, string(t), string(a))
		num, _ = strconv.Atoi(s)
	}
	return num
}

func maxDiff(num int) int {
    max_v := replace(num, '9')
	s := strconv.Itoa(num)
	min_v := 0
	if s[0] == '1' {
		min_v = replace(num, '0')
	} else {
		min_v = replace(num, '1')
	}
	return max_v - min_v
}


func main() {
	num := 123456
	maxDiff(num)
}
